package library

import (
	"errors"
	"github.com/jmoiron/sqlx"
	"vip_video/models"
)

type SystemConfigLibrary struct {
	db *sqlx.DB
}

func NewSystemConfigLibrary(db *sqlx.DB) *SystemConfigLibrary {
	f := &SystemConfigLibrary{
		db: db,
	}
	return f
}

func (scl *SystemConfigLibrary) Get(key string) (*models.ConfigModel, error) {
	var config models.ConfigModel
	if err := scl.db.Get(&config, "select * from fa_config where name = ? limit 1;", key); err != nil {
		return nil, errors.New("未找到配置")
	}
	return &config, nil
}
